using System.Diagnostics;
using static SmartSite.Common.CheckingNullArgument;

namespace SmartSite.Frame
{
    public abstract class WithMonitorDeviceSnFrame : BaseFrame
    {
        /// <summary>
        /// 硬件号. 16 byte 字符串. 紧邻 InfoLength 之后.
        /// </summary>
        protected IValueField<string> MonitorDeviceSnField { get; }
        public string MonitorDeviceSn
        {
            get => MonitorDeviceSnField.Value;
            set => MonitorDeviceSnField.Value = value;
        }

        protected WithMonitorDeviceSnFrame(byte[] buffer)
        : base(CheckingNull(buffer, nameof(buffer)))
        {
            MonitorDeviceSnField = CreateMonitorDeviceSnField();
            Debug.Assert(MonitorDeviceSnField.Index > InfoLengthField.Index);
            Debug.Assert(MonitorDeviceSnField.Index == InfoLengthField.EndIndex);
        }

        StringField CreateMonitorDeviceSnField() => new StringField(InfoLengthField, 16 << 3);

        protected ushort EvalInfoLength()
            => (ushort)(CRCField.Index - MonitorDeviceSnField.EndIndex).ToTakeUpBytes();

    }
}
